import { homeBrand, homeBanner } from '@/api/home'
const state = {
  brandList: [],
  slider: [] // 轮播图数据
}
const mutations = {
  setBrandList (state, value) {
    state.brandList = value
  },
  setSlider (state, value) {
    state.slider = value
  }
}
const actions = {
  async getBrandList ({ state, commit }) {
    if (state.brandList.length > 0) {
      return state.brandList
    }
    const { result } = await homeBrand(10)
    commit('setBrandList', result)
    return result
  },
  // 获取轮播图数据
  async getSliderList (store) {
    // 如果有数据就不要获取了
    if (store.state.slider.length > 0) {
      return store.state.slider
    }
    const res = await homeBanner()
    store.commit('setSlider', res.result)
    return res.result
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
